import {defineConfig} from 'tsup'
import copy from 'rollup-plugin-copy'
import './src/config/setEnv.js'

import packageJson from './package.json'

const prodPackages = Object.keys(packageJson.dependencies);

export default defineConfig({
	minify: true,
	splitting: false,
	sourcemap: false,
	clean: true,
	outDir: 'build/tsup',
	entry: ['src/index.ts'],
	format: ['cjs'],
	noExternal: [...prodPackages],
	plugins: [
		copy({
			targets: [
				{ src: 'public/**/*', dest: 'build/tsup/public' },
				{ src: 'pages/**/*', dest: 'build/tsup/pages' },
				{ src: 'fonts/**/*', dest: 'build/tsup/fonts' },
			],
			flatten: false
		}),
	],
	esbuildOptions(options, context) {
		options.define = {
			...options.define,
			'process.env': JSON.stringify(process.env),
		};
	}
})
